package com.torry.edss.application.job;

import com.torry.edss.application.biz.SyncDataBiz;
import com.torry.edss.application.biz.TacticBiz;
import com.torry.edss.application.cache.TradingDayCache;
import com.torry.edss.domain.enums.TacticMode;
import com.torry.edss.infras.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class FetchDataTask {

    @Resource
    private SyncDataBiz syncDataBiz;
    @Resource
    private TacticBiz tacticBiz;


    @Scheduled(cron = "0 55 15 * * ?")
    public void realTimePicking() {
        TradingDayCache.checkTodayIsTradingDay();
        tacticBiz.realTimePicking(TacticMode.CROSS_STAR);
    }

    /**
     * 交易日下午16：35 执行。 拉取每日基本行情数据
     */
    @Scheduled(cron = "0 35 16 * * ?")
    public void fetchMarketData() {
        TradingDayCache.checkTodayIsTradingDay();
        log.info("===== FetchDataTask.fetchMarketData Start =====");
        String today = DateUtil.getNowDate();
        syncDataBiz.syncAllCompanies();
        log.info("======= 同步两市股票 end =======");

        syncDataBiz.syncDayLines(today);
        log.info("======= 同步日线数据 end =======");

        syncDataBiz.syncLimitUps(today);
        log.info("======= 同步涨停股池 end =======");

        syncDataBiz.syncLimitDowns(today);
        log.info("======= 同步跌停股池 end =======");

        syncDataBiz.syncLimitBombs(today);
        log.info("======= 同步炸板股池 end =======");

        syncDataBiz.syncMarketSituation(today);
        log.info("======= 同步大盘行情 end =======");

        tacticBiz.hisPicking(today, TacticMode.CROSS_STAR);
        log.info("======= 战法选股 end =======");

        tacticBiz.refreshProfit(TacticMode.CROSS_STAR, 1);
        log.info("=======更新1日盈亏数据 end=======");

        tacticBiz.refreshProfit(TacticMode.CROSS_STAR, 5);
        log.info("=======更新5日盈亏数据 end=======");

        tacticBiz.refreshProfit(TacticMode.CROSS_STAR, 10);
        log.info("=======更新10日盈亏数据 end=======");

        log.info("===== FetchDataTask.fetchMarketData End =====");
    }
}